const dbConnect = require("../utils/dbConnect");


const addInfo = async (data) => {
    let _sql = `UPDATE user SET is_appointment = 1 , sessions_time = '${data.sessionTime}' , qrcode = '${data.qrcode}'  , sessions_id = '${data.sessionId}' WHERE token = '${data.token}'`;
    try {
        return await dbConnect(_sql);
    } catch (error) {
        return error;
    }
}

const getInfo = async (data) => {
    let _sql = `SELECT qrcode FROM user WHERE token = '${data.token}'`;
    try {
        return await dbConnect(_sql);
    } catch (error) {
        return error;
    }
}

// 修改预约
const updateInfo = async (data) => {
    let _sql = `UPDATE user SET is_appointment=0,sessions_time=NULL,sessions_id=NULL,qrcode=NULL WHERE token='${data.token}'`
    try {
        return await dbConnect(_sql);
    } catch (error) {
        return error;
    }
}

// 删除预约
const delInfo = async(data)=>{
    let _sql = `UPDATE user SET is_appointment = 0, sessions_time = NULL, qrcode = NULL, sessions_id = NULL WHERE token = '${data.token}' `;
    try {
        return await dbConnect(_sql);
    } catch (error) {
        return error;
    }
}

module.exports = { addInfo, getInfo, updateInfo ,delInfo};